package com.pai4j.jianlipai.service.jianlibot.templates;

import com.pai4j.common.enums.jianlibot.ResumeTemplateEnum;
import com.pai4j.common.exception.BusinessException;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import java.util.HashMap;
import java.util.Map;

/**
 * 简历模版工厂
 *
 * @author: CYM-pai
 * @date: 2025/05/06 14:13
 **/
@Component
public class ResumeTemplateFactory implements InitializingBean {


    @Resource
    private WebApplicationContext webApplicationContext;

    private static final Map<String, AbstractTemplateService> serviceMap = new HashMap<>();

    /**
     * 初始化行为数据服务
     */
    private void initServiceMap() {

        /***
         * 初始化简历模版服务
         */
        serviceMap.put(ResumeTemplateEnum.R001.getCode(), new ResumeTemplate001Service());
    }

    /**
     * 根据 behaviorType 获取 behaviorService
     *
     * @param code
     * @return
     */
    public static AbstractTemplateService getTemplateService(String code) {
        AbstractTemplateService templateService = serviceMap.get(code);
        if (templateService == null) {
            throw new BusinessException("不支持的简历模版");
        }
        templateService.setTemplateCode(code);
        return templateService;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        initServiceMap();
    }
}
